<template>
  <el-dialog title="店铺" :visible="visible" @close="hide">
    <el-form :model="form" ref="form">
      <el-form-item
        label="最大商品数量"
        :label-width="formLabelWidth"
        prop="goodsNumber"
      >
        <el-input-number
          :max="99999"
          v-model="form.maxGoodsNumber"
          placeholder="请输入商品最大数量"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="update(1)" v-if="form.id"
        >发布</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'editShop',
  props: {},
  data () {
    return {
      process: process,
      visible: false,
      formLabelWidth: '120px',
      form: {
        price: 0,
        deposit: 0,
        name: '',
        description: '',
        shippingFee: 0,
        shippingScope: 0,
        logo: [],
        rentedNumber: 0,
        goodsNumber: 0
      }
    }
  },
  methods: {
    show (item) {
      if (item && item.id) {
        this.form = {
          id: item.id,
          maxGoodsNumber: item.maxGoodsNumber
        }
      }
      this.visible = true
      this.$refs.form && this.$refs.form.clearValidate()
    },
    hide () {
      this.$refs.form.resetFields()
      this.fileList = []
      this.form = {
        id: 0,
        maxGoodsNumber: 80
      }
      this.visible = false
    },
    update (type) {
      debugger
      var url = `http://${
        process.env.NODE_ENV === 'development' ? 'localhost:9009' : 'qiucc.com'
      }/rentmall/shop/update`
      this.$refs.form.validate(validate => {
        if (validate) {
          const loading = this.$loading()
          this.$http
            .post(url, {
              pagination: {},
              query: {},
              form: {
                id: this.form.id,
                maxGoodsNumber: this.form.maxGoodsNumber
              }
            })
            .then(() => {
              this.$message.success('发布成功')
              this.hide()
              this.$emit('close')
            })
            .catch()
            .finally(() => {
              setTimeout(() => loading.close(), 500)
            })
        }
      })
    }
  }
}
</script>

<style>
#edit-goods {
  /* .{} */
}
</style>
